﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Mike
/// </summary>
public class Question
{
    int id;
    int no;
    string description;
    private Answer answer;
    public Answer Answer
    { 
        get { return answer; }
        set { answer = value; }
    }
    public int ID { get { return id; } }
    public int No { get { return no; } }
    public string Description { get { return description; } }
    //public Part Part { get { return part; } }

    public Question(){
        answer = new Answer();
    }

    public static List<Question> Load(Part part, IDbConnection connection)
    {
        string sql_script =
@"SELECT * FROM [Questions] WHERE [Questions].part_id = " + part.ID+ " ORDER BY [Questions].no";

        IDbCommand cmd = connection.CreateCommand();
        cmd.CommandText = sql_script;
        IDataReader dr = cmd.ExecuteReader();
        List<Question> lst = new List<Question>();

        while (dr.Read())
        {
            Question que = new Question();
            que.id = Convert.ToInt32(dr["id"].ToString());
            que.no = Convert.ToInt32(dr["no"].ToString());
            que.description = dr["description"].ToString();

            lst.Add(que);
        }
        dr.Close();
        return lst;
    }
}
